/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
typedef struct TreeNode TreeNode;
struct TreeNode* mirrorTree(struct TreeNode* root)//反转二叉树
{
    if (root == NULL)
    {
        return NULL;
    }
    else
    {
        TreeNode* right = root->right;
        root->right = mirrorTree(root->left);
        root->left = mirrorTree(right);
        return root;
    }
}
bool isSameTree(struct TreeNode* p, struct TreeNode* q)//判断是否相同
{
    if (p == NULL && q == NULL)//判断空节点
        return true;
    if (p == NULL && q != NULL || p != NULL && q == NULL)//判断两树结构
        return false;
    else if (p->val != q->val)//判断值
        return false;
    else
        return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}
bool isSymmetric(struct TreeNode* root) {
    if (root == NULL)
        return true;
    //反转二叉树的左子树
    TreeNode* newLeft = mirrorTree(root->left);
    //比较反转之后的子树和右子树
    return isSameTree(newLeft, root->right);
}